package com.ayf.payment.game.api.service.impl;

import com.ayf.payment.game.api.entity.TemplateEquipment;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.mapper.TemplateEquipmentMapper;
import com.ayf.payment.game.api.service.TemplateEquipmentService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TemplateEquipmentServiceImpl implements TemplateEquipmentService {

    @Resource
    private TemplateEquipmentMapper templateEquipmentMapper;

    @Override
    public boolean insertEquipments(List<TemplateEquipment> equipmentList) {
        if (equipmentList == null) {
            throw new ParameterException("添加赠送装备错误，参数不能为空");
        }
        return templateEquipmentMapper.insertEquipments(equipmentList) > 0;
    }

    @Override
    public List<TemplateEquipment> selectAllByTemplateId(String templateId) {
        TemplateEquipment temp = checkParameter(templateId);
        return templateEquipmentMapper.select(temp);
    }

    private TemplateEquipment checkParameter(String templateId) {
        if (StringUtils.isBlank(templateId)) {
            throw new ParameterException("模板id不能为空");
        }
        TemplateEquipment equipment = new TemplateEquipment();
        equipment.setTemplateId(templateId);
        return equipment;
    }

    @Override
    public boolean delEquipmentByTemId(String templateId) {
        TemplateEquipment temp = checkParameter(templateId);
        return templateEquipmentMapper.delete(temp) > 0;
    }
}


